/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Color;

/**
 *
 * @author Nordahl
 */
public class Setup2 extends javax.swing.JPanel {
    
    tvmGUI master;

    /**
     * Creates new form Setup2
     */
    public Setup2() {
        initComponents();
        LabSetup2Error.setVisible(false);
        LabSetup2ErrorList.setVisible(false);
        //LabSetup2Time.setText(master.time.toString().substring(0,19));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabSetup2Info = new javax.swing.JLabel();
        LabSetup2Time = new javax.swing.JLabel();
        LabSetup2Title = new javax.swing.JLabel();
        LabSetup2TypeDA = new javax.swing.JLabel();
        InSetup2TypeDA = new javax.swing.JTextField();
        LabSetup2TypeENG = new javax.swing.JLabel();
        InSetup2TypeENG = new javax.swing.JTextField();
        LabSetup2PricePZ = new javax.swing.JLabel();
        InSetup2PricePZ = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        ListSetup2TicketList = new javax.swing.JList();
        LabSetup2TicketList = new javax.swing.JLabel();
        ButSetup2AddM = new javax.swing.JButton();
        ButSetup2Save = new javax.swing.JButton();
        ButSetup2Back = new javax.swing.JButton();
        LabSetup2Error = new javax.swing.JLabel();
        LabSetup2ErrorList = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 600));

        LabSetup2Time.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabSetup2Time.setText(" ");

        LabSetup2Title.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        LabSetup2Title.setText("Opret billetter");

        LabSetup2TypeDA.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup2TypeDA.setText("Indtast navnet på billettypen på dansk.");

        LabSetup2TypeENG.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup2TypeENG.setText("Indtast navnet på billettypen på engelsk.");

        LabSetup2PricePZ.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup2PricePZ.setText("Indtast pris pr. zone.");

        ListSetup2TicketList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        ListSetup2TicketList.setFocusable(false);
        ListSetup2TicketList.setVisibleRowCount(10);
        jScrollPane1.setViewportView(ListSetup2TicketList);

        LabSetup2TicketList.setText("Oprettede billetter.");

        ButSetup2AddM.setText("Tilføj flere");
        ButSetup2AddM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButSetup2AddMActionPerformed(evt);
            }
        });

        ButSetup2Save.setText("Gem og afslut");
        ButSetup2Save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButSetup2SaveActionPerformed(evt);
            }
        });

        ButSetup2Back.setText("Tilbage");
        ButSetup2Back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButSetup2BackActionPerformed(evt);
            }
        });

        LabSetup2Error.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        LabSetup2Error.setForeground(new java.awt.Color(255, 0, 0));
        LabSetup2Error.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup2Error.setText("Fejl - Ugyldig indtastning");

        LabSetup2ErrorList.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        LabSetup2ErrorList.setForeground(new java.awt.Color(255, 0, 0));
        LabSetup2ErrorList.setText("Fejl - Ingen billetter oprettet");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(LabSetup2Info)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(LabSetup2Time, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(LabSetup2Title)
                        .addGap(315, 315, 315))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabSetup2TicketList, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(LabSetup2TypeDA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(InSetup2TypeDA)
                            .addComponent(LabSetup2TypeENG, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(InSetup2TypeENG)
                            .addComponent(InSetup2PricePZ)
                            .addComponent(LabSetup2PricePZ, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(125, 125, 125))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(LabSetup2Error)
                        .addGap(166, 166, 166))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ButSetup2Back, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(ButSetup2Save)
                .addGap(18, 18, 18)
                .addComponent(ButSetup2AddM, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
            .addGroup(layout.createSequentialGroup()
                .addGap(128, 128, 128)
                .addComponent(LabSetup2ErrorList)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabSetup2Info)
                    .addComponent(LabSetup2Time))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LabSetup2Title)
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabSetup2TypeDA)
                    .addComponent(LabSetup2TicketList))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(InSetup2TypeDA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(LabSetup2TypeENG)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(InSetup2TypeENG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(LabSetup2PricePZ)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(InSetup2PricePZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(LabSetup2Error))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(LabSetup2ErrorList)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 214, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButSetup2AddM, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ButSetup2Save, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ButSetup2Back, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24))
        );
    }// </editor-fold>//GEN-END:initComponents

    public void addTicketToListSetup2 (int PricePZ, String TypeDA, String TypeENG) {       
        LabSetup2Error.setVisible(false);
        LabSetup2ErrorList.setVisible(false);
        master.CT.addTicket(PricePZ, TypeDA, TypeENG, master.startZone);
        InSetup2TypeDA.setText(""); InSetup2TypeENG.setText(""); InSetup2PricePZ.setText("");
        master.ListContent.add(TypeDA+", "+TypeENG+", "+PricePZ+", "+master.startZone);
        ListSetup2TicketList.setListData(master.ListContent.toArray());
        //CBWelcomeDAType.addItem(TypeDA);
    }
    
    public void checkFieldsSetup2 (int PricePZ, String TypeDA, String TypeENG) {
        if(PricePZ == -1)
        {
            LabSetup2Error.setVisible(true);
            LabSetup2PricePZ.setForeground(Color.red);
        }
        else
        {
            LabSetup2PricePZ.setForeground(Color.black);
        }
        if(TypeDA.equals(""))
        {
            LabSetup2Error.setVisible(true);
            LabSetup2TypeDA.setForeground(Color.red);
        }
        else
        {    
            LabSetup2TypeDA.setForeground(Color.black);
        }
        if (TypeENG.equals(""))
        {
            LabSetup2Error.setVisible(true);
            LabSetup2TypeENG.setForeground(Color.red);
        }
        else
        {
            LabSetup2TypeENG.setForeground(Color.black);
        }
    }
    
   
        
//----------------------------ACTIONS------------------------------------
    
    private void ButSetup2AddMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButSetup2AddMActionPerformed
        String TypeDA = InSetup2TypeDA.getText().trim();
        String TypeENG = InSetup2TypeENG.getText().trim();
        int PricePZ = master.isInteger(InSetup2PricePZ.getText().trim());
        checkFieldsSetup2(PricePZ, TypeDA, TypeENG);
        LabSetup2ErrorList.setVisible(false);
        if (PricePZ !=-1 && !TypeDA.equals("") && !TypeENG.equals(""))
        {
            addTicketToListSetup2(PricePZ, TypeDA, TypeENG);
        }
    }//GEN-LAST:event_ButSetup2AddMActionPerformed

    private void ButSetup2SaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButSetup2SaveActionPerformed
        String TypeDA = InSetup2TypeDA.getText().trim();
        String TypeENG = InSetup2TypeENG.getText().trim();
        int PricePZ = master.isInteger(InSetup2PricePZ.getText());
        if (ListSetup2TicketList.getModel().getSize() == 0)
        {
            if (PricePZ !=-1 && !TypeDA.equals("") && !TypeENG.equals(""))
            {
                addTicketToListSetup2(PricePZ, TypeDA, TypeENG);
                //switchWindow(Setup2, WelcomeDA);
                //LabWelcomeDAInfo.setText("Maskin ID: "+master.hardID+"  Zone: "+master.startZone);
                return;
            }
            else
            {
                LabSetup2ErrorList.setVisible(true);
            }
        }
        else
        {
            LabSetup2ErrorList.setVisible(false);
        }
        checkFieldsSetup2(PricePZ, TypeDA, TypeENG);
        if (!master.ListContent.isEmpty())
        {
            if (PricePZ ==-1 && TypeDA.equals("") && TypeENG.equals(""))
            {
                //switchWindow(Setup2, WelcomeDA);
            }
            else if (PricePZ !=-1 && !TypeDA.equals("") && !TypeENG.equals(""))
            {
                addTicketToListSetup2(PricePZ, TypeDA, TypeENG);
                //switchWindow(Setup2, WelcomeDA);
                //LabWelcomeDAInfo.setText("Maskin ID: "+master.hardID+"  Zone: "+master.startZone);
            }
            else
            {
                checkFieldsSetup2(PricePZ, TypeDA, TypeENG);
            }
        }
    }//GEN-LAST:event_ButSetup2SaveActionPerformed

    private void ButSetup2BackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButSetup2BackActionPerformed
        //        //Change window to previous window
        //        switchWindow(Setup2, Setup1);
        //Returning all warning labels to default
        LabSetup2TypeENG.setForeground(Color.black);
        LabSetup2TypeDA.setForeground(Color.black);
        LabSetup2PricePZ.setForeground(Color.black);
        LabSetup2Error.setVisible(false);
        LabSetup2ErrorList.setVisible(false);
        //        //Clearing all ArrayLists and Jlist
        //        ListSetup2TicketList.removeAll();
        //        ListContent.clear();
        //        CT.ClearArray();
        /*forr (int i = 2; i <= CBWelcomeDAType.getItemCount()+3; i++) { //+1 to avoid-
            CBWelcomeDAType.removeItemAt(i);             // deleting first item
        }*/
        //        CBWelcomeDAType.removeAll();
        //        CBWelcomeDAType.addItem("Vælg billettype...");
        //Clearing all ArrayLists and Jlist
        ListSetup2TicketList.removeAll();
        master.ListContent.clear();
        master.CT.ClearArray();
        //Change window to previous window
        //switchWindow(Setup2, Setup1);
    }//GEN-LAST:event_ButSetup2BackActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButSetup2AddM;
    private javax.swing.JButton ButSetup2Back;
    private javax.swing.JButton ButSetup2Save;
    private javax.swing.JTextField InSetup2PricePZ;
    private javax.swing.JTextField InSetup2TypeDA;
    private javax.swing.JTextField InSetup2TypeENG;
    private javax.swing.JLabel LabSetup2Error;
    private javax.swing.JLabel LabSetup2ErrorList;
    private javax.swing.JLabel LabSetup2Info;
    private javax.swing.JLabel LabSetup2PricePZ;
    private javax.swing.JLabel LabSetup2TicketList;
    private javax.swing.JLabel LabSetup2Time;
    private javax.swing.JLabel LabSetup2Title;
    private javax.swing.JLabel LabSetup2TypeDA;
    private javax.swing.JLabel LabSetup2TypeENG;
    private javax.swing.JList ListSetup2TicketList;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
